//package com.jsyl.qies.business.service.impl;
//
//import com.jsyl.qies.business.constant.EvaluationStandardConstant;
//import com.jsyl.qies.business.domain.TrainStudentScheduleQuestion;
//import com.jsyl.qies.business.domain.TrainStudentScheduleRecord;
//import com.jsyl.qies.business.dto.EnteringDTO;
//import com.jsyl.qies.business.dto.ScheduleRecordListDTO;
//import com.jsyl.qies.business.dto.TopicScoreDTO;
//import com.jsyl.qies.business.mapper.ScheduleDetailMapper;
//import com.jsyl.qies.business.mapper.TrainStudentScheduleQuestionMapper;
//import com.jsyl.qies.business.mapper.TrainStudentScheduleRecordMapper;
//import com.jsyl.qies.business.service.IPerformanceService;
//import com.jsyl.qies.business.vo.ClassScheduleVO;
//import com.jsyl.qies.business.vo.StudentBasicsVO;
//import com.jsyl.qies.business.vo.StudentScheduleRecordVO;
//import com.jsyl.qies.common.utils.IntervalUtil;
//import org.apache.commons.collections.CollectionUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//
//@Service
//public class PerformanceServiceImpl implements IPerformanceService {
//
//    @Autowired
//    private ScheduleDetailMapper scheduleDetailMapper;
//
//    @Autowired
//    private TrainStudentScheduleQuestionMapper trainStudentScheduleQuestionMapper;
//
//    @Autowired
//    private TrainStudentScheduleRecordMapper trainStudentScheduleRecordMapper;
//
//    @Override
//    public List<ClassScheduleVO> findList(Long teacherId, ScheduleRecordListDTO scheduleRecordListDTO) {
//        return scheduleDetailMapper.selectByTeacherIdAndTime(teacherId, scheduleRecordListDTO.getScheduleTime().replaceAll("-", ""));
//    }
//
//    @Override
//    public List<StudentScheduleRecordVO> entering(ScheduleRecordListDTO scheduleRecordListDTO) {
//        List<StudentScheduleRecordVO> list = new ArrayList<>();
//        String scheduleTime = scheduleRecordListDTO.getScheduleTime();
//        List<TrainStudentScheduleQuestion> trainStudentScheduleQuestions = trainStudentScheduleQuestionMapper.selectQuestions(scheduleRecordListDTO.getStudentId(), scheduleTime.substring(0, 6));
//        List<TrainStudentScheduleRecord> trainStudentScheduleRecords = trainStudentScheduleRecordMapper.selectByStudentIdAndDay(scheduleRecordListDTO.getStudentId(), scheduleRecordListDTO.getScheduleTime());
//        for (TrainStudentScheduleQuestion trainStudentScheduleQuestion : trainStudentScheduleQuestions) {
//            StudentScheduleRecordVO vo = new StudentScheduleRecordVO();
//            vo.setCenterId(trainStudentScheduleQuestion.getCenterId());
//            vo.setStudentId(trainStudentScheduleQuestion.getStudentId());
//            vo.setTeacherId(trainStudentScheduleQuestion.getTeacherId());
//            vo.setQuestionNum(trainStudentScheduleQuestion.getQuestionNum());
//            vo.setQuestionType(trainStudentScheduleQuestion.getQuestionType());
//            vo.setQuestionName(trainStudentScheduleQuestion.getQuestionName());
//            vo.setInputType(trainStudentScheduleQuestion.getInputType());
//            if (CollectionUtils.isEmpty(trainStudentScheduleRecords)) {
//                vo.setGrade(4);
//            } else {
//                for (TrainStudentScheduleRecord trainStudentScheduleRecord : trainStudentScheduleRecords) {
//                    if (trainStudentScheduleRecord.getQuestionNum().equals(trainStudentScheduleQuestion.getQuestionNum()) && trainStudentScheduleRecord.getQuestionType().equals(trainStudentScheduleQuestion.getQuestionType())) {
//                        vo.setGrade(trainStudentScheduleRecord.getGrade());
//                    }
//                }
//            }
//            list.add(vo);
//        }
//        return list;
//    }
//
//    @Override
//    public List<StudentBasicsVO> studentBasics(Long teacherId, String scheduleTime, Integer projectType) {
//        // List<StudentBasicsVO> list = scheduleDetailMapper.selectByStudentBasics(teacherId, scheduleTime);
//        List<StudentBasicsVO> list = trainStudentScheduleQuestionMapper.selectStudent(teacherId, scheduleTime.substring(0, 6), projectType);
//        return list;
//    }
//
//    @Override
//    public int saveEntering(EnteringDTO enteringDTO) {
//        List<TopicScoreDTO> list = enteringDTO.getList();
//        int i = 0;
//        for (TopicScoreDTO topicScoreDTO : list) {
//            if (null != topicScoreDTO.getTotalNum() && null != topicScoreDTO.getCompleteNum()) {
//                TrainStudentScheduleRecord trainStudentScheduleRecord = new TrainStudentScheduleRecord();
//                trainStudentScheduleRecord.setCenterId(topicScoreDTO.getCenterId());
//                trainStudentScheduleRecord.setStudentId(topicScoreDTO.getStudentId());
//                trainStudentScheduleRecord.setTeacherId(topicScoreDTO.getTeacherId());
//                trainStudentScheduleRecord.setScheduleTime(enteringDTO.getScheduleTime());
//                trainStudentScheduleRecord.setQuestionNum(topicScoreDTO.getQuestionNum());
//                trainStudentScheduleRecord.setQuestionType(topicScoreDTO.getQuestionType());
//                trainStudentScheduleRecord.setTotalNum(topicScoreDTO.getTotalNum());
//                trainStudentScheduleRecord.setCompleteNum(topicScoreDTO.getCompleteNum());
//                double scoreRate = new BigDecimal((float) topicScoreDTO.getCompleteNum() / topicScoreDTO.getTotalNum()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
//                if (IntervalUtil.isInTheInterval(String.valueOf(scoreRate), EvaluationStandardConstant.HAS_BEEN_STABLE)) {
//                    trainStudentScheduleRecord.setGrade(1);
//                } else if (IntervalUtil.isInTheInterval(String.valueOf(scoreRate), EvaluationStandardConstant.NEED_CONSOLIDATE)) {
//                    trainStudentScheduleRecord.setGrade(2);
//                } else if (IntervalUtil.isInTheInterval(String.valueOf(scoreRate), EvaluationStandardConstant.NOT_REACH)) {
//                    trainStudentScheduleRecord.setGrade(3);
//                }
//                trainStudentScheduleRecord.setScoreRate(scoreRate);
//                trainStudentScheduleRecord.setSubmitTime(new Date());
//                i += trainStudentScheduleRecordMapper.insert(trainStudentScheduleRecord);
//            }
//        }
//        return i;
//    }
//
//}
